home *** CD-ROM | disk | FTP | other *** search
- /*
- * © Copyright Jeff Francis 1990
- * All rights reserved
- *
- * $Id$
- *
- * Description - Contains the C main routine that glues together
- * the default After Dark calling mechanism to an object/message
- * based interface. Page references are to "After Dark
- * Programmer's Manual."
- */
-
- #include <SetUpA4.h>
- #include <oops.h>
- #include "ADGMTypes.h"
- #include "GlueCode.h"
-
- pascal OSErr main(Handle *storage, RgnHandle blankRgn, eMessage message, GMParamBlockPtr params)
- {
- OSErr status = noErr;
-
- /*
- * Setup THINK C's A4 global world.
- */
- RememberA0();
- SetUpA4();
-
- /*
- * If we've allocated storage then lock it down.
- */
- if (*storage != 0) {
- MoveHHi(*storage);
- HLock(*storage);
- }
-
- switch (message) {
- case kInitialize:
- /*
- * Create a new object and make storage point to it. If
- * the new fails then return with an error (Page 18 - Errors).
- * If the new is successful, lock the object down because
- * we wouldn't have locked it down before. Finally, send
- * the object an Initialize message.
- */
- if ((*storage = new(SUBCLASS)) == 0)
- return kModuleError;
- MoveHHi(*storage);
- HLock(*storage);
- status = ((CAfterDark *)*storage)->Initialize(blankRgn, params);
- break;
-
- case kBlank:
- /*
- * Send a Blank message to the object.
- */
- status = ((CAfterDark *)*storage)->Blank(blankRgn, params);
- break;
-
- case kDrawFrame:
- /*
- * Send a DrawFrame message to the object.
- */
- status = ((CAfterDark *)*storage)->DrawFrame(blankRgn, params);
- break;
-
- case kClose:
- /*
- * Send a Close message to the object, delete it and then
- * set storage to NIL.
- */
- status = ((CAfterDark *)*storage)->Close(blankRgn, params);
- delete(*storage);
- *storage = 0;
- break;
-
- default: /* kButtonMessage */
- /*
- * If we have a ButtonMessage, then send the object the
- * ButtonMessage.
- */
- if (message >= kButtonMessage)
- status = ((CAfterDark *)*storage)->ButtonMessage(blankRgn, params, message);
- break;
-
- case kModuleSelected:
- /*
- * Send a ModuleSelected message to the object.
- */
- status = ((CAfterDark *)*storage)->ModuleSelected(blankRgn, params);
- break;
-
- case kDoHelp:
- /*
- * Send a DoHelp message to the object.
- */
- status = ((CAfterDark *)*storage)->DoHelp(blankRgn, params);
- break;
- }
-
- /*
- * If we've allocated storage then we should unlock what we've
- * previously locked.
- */
- if (*storage != 0)
- HUnlock(*storage);
-
- /*
- * Restore THINK C's A4 global environment.
- */
- RestoreA4();
-
- return status;
- }